fn main() {
    println!("{}", Solution::convert("PAYPALISHIRING".to_string(), 3));
}

struct Solution;

impl Solution {
    pub fn convert(s: String, num_rows: i32) -> String {
        let num_rows = num_rows as usize;
        let len = s.chars().count();
        if num_rows == 1 || num_rows >= len {
            return s;
        } else {
            let l = (len / (num_rows * 2 - 2) + 1) * (num_rows - 1);
            println!("{}", l);
            let mut x = 0;
            let mut y = 0;
            let mut list = vec![' '; l * num_rows];
            for c in s.chars() {
                list[x + y * l] = c;
                if x % (num_rows -1) == 0 && y < (num_rows - 1) {
                    y = y + 1;
                } else {
                    x = x + 1;
                    y = y - 1;
                }
            }
            return list.into_iter().filter(|x| *x != ' ').collect();
        }
    }
}
